package practica;

import java.io.IOException;
import practica.analizadoresAntlr.*;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import practica.arboles.*;


public class Procesador {
	public static void main(String[] args) throws IOException, RecognitionException {
		if (args[0].endsWith(".txt")){
			System.out.println ("Analizando fichero Expresiones");
			CharStream cs = new ANTLRFileStream(args[0]);
			ExpresionesLexer lex = new ExpresionesLexer(cs);
			CommonTokenStream tokens = new CommonTokenStream(lex);
			ExpresionesParser parser = new ExpresionesParser(tokens);
			parser.setTreeAdaptor(new MiArbolAdaptor());
            ExpresionesParser.entrada_return expReturn = parser.entrada();
            CommonTree expTree = (CommonTree) expReturn.getTree();
            System.out.println("Arbol expresiones = "+expTree.toStringTree());
            CommonTreeNodeStream nodes = new CommonTreeNodeStream(expTree);
            ExpresionesEvaluator evaluator = new ExpresionesEvaluator(nodes, parser.funciones);
            evaluator.entrada();
            ASTFrame expEvaluator = new ASTFrame("Arbol Abstracto sintactico (Evaluador): " + args[0], expTree);
            expEvaluator.setVisible(true);
            System.out.println ("done!");
		}
	
	}
}


